# 1、编写函数，求1+2+3+…N的和
# def sum(x,y):
#     num =0
#     for item in range(x,y):
#         num += item
#     return num
# N = int(input("输入数字"))
# print(sum(1,N))

# def add(n,m):
#     x = 0
#     for i in range(n,m):
#         x+=i
#     return x
# N = int(input('输入数字'))
# add(1,N)
# print(add(1,N))

# def add(x,y):
#     n=0
#     for i in range(x,y):
#         n+=i
#     return n
# N=int(input("输入数字"))
# add(1,N)
# print(add(1,N))

# def max(n):
#     sum =0
#     for i in range(n):
#         sum+=i
#     return sum
# print(max(5))




# 2、编写一个函数，求多个数中的最大值
# def max_(*num):
#     return max(*num)
# max_(67,7,89,100)
# print(max_(67,7,89,100))

# def max(*a):
#     list=[]
#     for i in a:
#         list.append(i)
#     list.sort(reverse=True)
#     return list[0]
#
# print(max(76,89,3))






# 3、编写一个函数，提取指定字符串中所有的字母，然后拼接在一起产生一个新的字符串
# def str_(str):
#     list =[]
#     str=""
#     for i in range(str):
#         list.append(i)
#     list.sort(reverse=True)
#     return list[0]
# print(str("gwgfcyuiqfdqugi,tgw7gtyxg"))

# def str_(str):
#     list =[]
#     str=""
#     for i in range(65,123):
#         if i not in (91,92,93,94,95,96):
#             list.append(i)
#     for i in str:
#         if ord(i) in list:
#             str+=i
#     return str
# print(str_("etgchgsu,dggQG"))

# def str1(*str_):
#     str= ""
#     list=[]
#     for i in range(65,123):
#         if i not in (91,92,93,94,95,96,97):
#             list.append(i)
#     for i in str:
#         if ord(i) in list:
#             str+=i
#     return str
# print(str1("gdtfwgfxgf//.","y7dgygdf558"))
#
# 4、写一个函数，求多个数的平均值
# def avg(*b):
#     sum=0
#     for i in b:
#         sum+=i
#     return sum//len(b)
# print(avg(3,4,5))

# 5、写一个自己的len函数，统计指定序列中元素的个数
# def len(*a):
#     sum = 0
#     for i in a:
#         sum+=1
#     return sum
# print(len(2,76,56))
# def len(*a):
#     sum=0
#     for i in a:
#         sum+=1
#     return sum
# print(len(45,76,34,2,8))

# 6、写一个自己的max函数，获取指定序列中元素的最大值。如果序列是字典，取字典值的最大值

# def max(a):
#     list=[]
#     try:
#         if isinstance(a,dict):
#             for i in a.values:
#                 list.append(i)
#                 list.sort(reverse=True)
#                 return list[0]
#         else:
#             return max(a)
#     except:
#         return "输入的是数字或者小数类型，长度不支持统计"
# print(max({"a":"sh","d":"fwf"}))

# 7、写函数，判断用户传入的对象（字符串，列表，元组）长度是否大于5
# def hh(type):
#     if isinstance(type,list):
#         if len(type)<5:
#             return"传入的是{}对象，长度不大于5".format(type)
#         elif len(type)>5:
#             return"传入的是{}对象，长度大于5".format(type)
#     if isinstance(type,str):
#         if len(type)<5:
#             return " 传入的是{}对象，长度大于5".format(type)
#         elif len(type)>5:
#             return"传入的是{}对象，长度不大于5".format(type)
#     if isinstance(type,tuple):
#         if len(type)<5:
#             return "传入的是{}对象，长度不大于5".format(type)
#         elif len(type)>5:
#             return "传入的{}对象，长度大于5".format(type)
#
#
# print(hh([1,2,3,4,5,6]))
# print(hh("12345567"))
# print(hh((1,2,3,4)))



# 8、封装函数，可以判断一个数字是否为偶数
# def num(a):
#     if a%2==0:
#         return "是偶数"
#     else:
#         return "不是偶数"
# print(num(1))

# 9、封装函数，可以实现1-n之间所有偶数的打印
# def ou(*a):
#     sum=0
#     for i in a:
#         if i %2==0:
#             sum+=1
#         return sum
# print(ou(1,2,3,4,5,8,10))

# def ou(*a):
#     list1=[]
#     for i in a:
#         if i%2==0:
#             list1.append(i)
#     return list1
# print(ou(1,2,3,4,5,6))


# 9.1、封装函数，可以实现1-n之间所有偶数的和
# def ou(*a):
#     list=[]
#     sum=0
#     for i in a:
#         if i %2==0:
#             list.append(i)
#     for i in list:
#             sum+=i
#     return sum
# print(ou(1,2,3,4,5,6))

#10、定义一个函数，向函数内传入形参num, num1, num2，如果num小于100，则计算num1
# 和 num2的积并打印；否则计算num1和num2的和，然后打印输出；
# def hh(num,num1,num2):
#     if num<100:
#         print(num1*num2)
#     elif num>100:
#         print(num1+num2)
# print(hh(234,5,6))
# print(hh(23,5,7))

# 11 、定义一个函数，向函数内传入形参username，password，当username值为josh且password值为字符串josh123时，
# 返回“登录成功”；否则返回“请重新登录”
# def hh(username,password):
#     username =str(input("输入您的用户名"))
#     password =int(input("输入您的密码"))
#     if username =="josh" and password ==123:
#         print("登录成功")
#         return"登录成功"
#     else:
#         print("登录失败")
#         return("登录失败")
#
# print(hh("josh",123))

# 12、封装函数，可以完成列表的倒序，不使用内置函数（解题思路：冒泡排序）
# def hh(list1):
#     for i in list1:
#         list1.sort(reverse=True)
#     return list1
# print(hh([1,5,6,3,8]))

# def sort_(arrays):
#     for i in range(len(arrays)): # 第一层循环
#         for j in range(len(arrays)-i): #  第二层循环，主要目的是为了两个数去比对
#             if arrays[i] > arrays[j]: # 0 1
#                 arrays[i],arrays[j] = arrays[j],arrays[i]
#     return arrays
# print(sort_([99,101,96,999]))

# n1 = [-7, -12, -1, -9]
# n2 = 'abcdpzasdz'
# n3 = {'小明': 90, '张三': 76, '路飞': 30, '小花': 98}
# def max_content(x):
#     max_num = 0
#     if type(x) in (str, list):
#         max_num = max(x)
#         print(max_num)
#     elif type(x) == dict:
#         max_num = max([x[i] for i in x])
#         print(max_num)
#     return max_num
#
# max_content(n1)
# max_content(n2)
# max_content(n3)


# 13、列表深度不可知，并且列表内部还会有二维数组，要求拼接出的新列表从左到有面顺序不变
# def hh(a):
#     list1=[]
#     for i in a:
#         if isinstance(i,list):
#             list1.extend(i)
#         else:
#             list1.append(i)
#     return list1
# a=[1,4]
# b=[56,8]
# c=[]
# c.extend(a)
# c.extend(b)
# print(c)


# def hh(a):
#     list1=[]
#     for i in a:
#         if isinstance(i,list):
#             list1.extend(i)
#         else:
#             list1.append(i)
#     return list1
# a=[2,3,4,[1,2]]
# b=[579,576]
# c=[]
# c.extend(a)
# c.extend(b)
# print(hh(a))
#
# prina=[1,2,3[11,23,3],23,6]t(a)


# arraylist= [123,[1,2,3],456,[7,8,9]] # list  [123,1,2,3,456]

# def new(arraylist):
#     new_list = []
#     for i in arraylist: # 获取数据
#         # 判断，里面的结构有没有二维数组
#         if isinstance(i,list):
#             new_list.extend(i) # 追加到列表末尾
#         else:
#             new_list.append(i)
#     return new_list
# print(new(arraylist))












